package com.itheima.zhlx.service.impl;

import com.itheima.zhlx.dao.GoodsDao;
import com.itheima.zhlx.entity.PageBean;
import com.itheima.zhlx.entity.PageTotal;
import com.itheima.zhlx.entity.Result;
import com.itheima.zhlx.pojo.Goods;
import com.itheima.zhlx.service.GoodsServlce;

import java.util.List;

public class GoodsServlceImpl implements GoodsServlce {
    private GoodsDao goodsDao =new GoodsDao();
    @Override
    public PageTotal goodfindAll(PageBean pageBean) {
        Integer currentPage = pageBean.getCurrentPage();
        Integer pageSize = pageBean.getPageSize();
        List<Goods> goods = goodsDao.goodsfindAll(((currentPage - 1) * pageSize), pageSize);
        Long aLong = goodsDao.countTotal();
        PageTotal pageTotal =new PageTotal();
        pageTotal.setTotal(aLong);
        pageTotal.setRows(goods);
        return pageTotal;
    }

    @Override
    public Integer addGoods(Goods goods) {
        return goodsDao.addGoodsDao(goods);
    }

    /**
     * 删除商品
     * @param id
     * @return
     */
    @Override
    public Integer deleteGoods(String id) {
        return goodsDao.deleteDao(id);
    }
}
